package com.cn;

import com.cn.pb.BasePb.Base;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;


public class ChannelIoHandler extends SimpleChannelInboundHandler<Base> {
	private ICommandPool commandPool;

	public ChannelIoHandler(ICommandPool commandPool) {
		this.commandPool = commandPool;
	}

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, Base msg) throws Exception {
		commandPool.action(ctx, msg);
	}

	@Override
	public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
		super.channelRegistered(ctx);
		LogHelper.CHANNEL_LOGGER.info("channel Registered");
	}

	@Override
	public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
		super.channelUnregistered(ctx);
		LogHelper.CHANNEL_LOGGER.info("channel Unregistered");
	}

	@Override
	public void channelActive(ChannelHandlerContext ctx) throws Exception {
		super.channelActive(ctx);
		LogHelper.CHANNEL_LOGGER.info("channel Active");
	}

	@Override
	public void channelInactive(ChannelHandlerContext ctx) throws Exception {
		super.channelInactive(ctx);
		LogHelper.CHANNEL_LOGGER.info("channel Inactive");
	}

	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
		super.exceptionCaught(ctx, cause);
		LogHelper.CHANNEL_LOGGER.info("channel Caught");
	}

}
